import D2Ext


class DllBase(object):

    @staticmethod
    def d2game():
        return D2Ext.Memory_GetDllBase_D2Game()

    @staticmethod
    def d2client():
        return D2Ext.Memory_GetDllBase_D2Client()

    @staticmethod
    def d2common():
        return D2Ext.Memory_GetDllBase_D2Common()


class CMemory(object):
    def __init__(self, start_addr, auto_increase=False):
        self.start_addr = start_addr
        self.auto_increase = auto_increase
        self.current_addr = self.start_addr

    def get_byte(self, offset):
        ret = D2Ext.Memory_GetByte(self.current_addr, offset)
        self.current_addr += 1 if self.auto_increase else 0
        return ret

    def get_word(self, offset):
        ret = D2Ext.Memory_GetWord(self.current_addr, offset)
        self.current_addr += 2 if self.auto_increase else 0
        return ret

    def get_dword(self, offset):
        ret = D2Ext.Memory_GetDword(self.current_addr, offset)
        self.current_addr += 4 if self.auto_increase else 0
        return ret

    def get_long(self, offset):
        ret = D2Ext.Memory_GetLong(self.current_addr, offset)
        self.current_addr += 4 if self.auto_increase else 0
        return ret

    def get_pointer(self, offset):
        ret = D2Ext.Memory_GetPointer(self.current_addr, offset)
        return ret

    def get_byte_pointer(self, offset):
        ret = D2Ext.Memory_GetBytePointer(self.current_addr, offset)
        return ret

    def get_widebyte_pointer(self, offset):
        ret = D2Ext.Memory_GetWideBytePointer(self.current_addr, offset)
        return ret

    def set_byte(self, offset, val):
        ret = D2Ext.Memory_SetByte(self.current_addr, offset, val)
        self.current_addr += 1 if self.auto_increase else 0
        return ret

    def set_char(self, offset, val):
        ret = D2Ext.Memory_SetChar(self.current_addr, offset, val)
        self.current_addr += 1 if self.auto_increase else 0
        return ret

    def set_word(self, offset, val):
        ret = D2Ext.Memory_SetWord(self.current_addr, offset, val)
        self.current_addr += 2 if self.auto_increase else 0
        return ret

    def set_short(self, offset, val):
        ret = D2Ext.Memory_SetShort(self.current_addr, offset, val)
        self.current_addr += 2 if self.auto_increase else 0
        return ret

    def set_dword(self, offset, val):
        ret = D2Ext.Memory_SetDword(self.current_addr, offset, val)
        self.current_addr += 4 if self.auto_increase else 0
        return ret

    def set_long(self, offset, val):
        ret = D2Ext.Memory_SetLong(self.current_addr, offset, val)
        self.current_addr += 4 if self.auto_increase else 0
        return ret
